import myConfig from '@/myConfig.js'
import {
	showToast
} from '@/util/toast.js'
import * as storage from '@/util/storage.js'
//异步请求
export default function request(param) {
	const httpDefaultOpts = {
		url: `${myConfig.app.baseUrl}${param.url}`,
		data: param.data || {},
		method: param.method || 'POST',
		header: {
			// 'content-type': 'application/json',
			'access-token': storage.getToken(),
			'language': storage.getLanguage()
		},
	}
	return new Promise((resolve, reject) => {
		uni.request(httpDefaultOpts).then(response => {
			const data = response.data
			if (data.code !== '200') {
				handleError(data)
			}
			resolve(data)
		}).catch(response => {
			console.error(response)
			showToast(response, 'none', 1000, false) //'未知错误'
		})
	})
}

function handleError(data) {
	const {
		code,
		msg
	} = data
	if(code === ''){
		
	}
	showToast(msg, null, 2000, false)
}
